home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7448 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: pki-nbg.philips.de!usenet
  2. From: ln_hwe@hln56.pki-nbg.philips.de (Harald Wellmann)
  3. Newsgroups: comp.object,comp.lang.c++
  4. Subject: Re: A design question
  5. Date: 23 Feb 1996 09:10:38 +0100
  6. Organization: Lucent Technologies
  7. Sender: ln_hwe@hln56.pki-nbg.philips.de
  8. Message-ID: <pvcybpuqx6p.fsf@hln56.pki-nbg.philips.de>
  9. References: <1996Feb22.234825.18755@dcs.warwick.ac.uk>
  10. NNTP-Posting-Host: hln56.pki-nbg.philips.de
  11. In-reply-to: miro@dcs.warwick.ac.uk's message of Thu, 22 Feb 1996 23:48:25 GMT
  12. X-Newsreader: Gnus v5.1
  13.  
  14. In article <1996Feb22.234825.18755@dcs.warwick.ac.uk> miro@dcs.warwick.ac.uk (Miroslav J Walker) writes:
  15.  
  16.    I'm trying to model input from a user being processed over a series of
  17.    steps.
  18.    Input is parsed, put into a queue and then interpreted on a timer. My
  19.    question is how to model the idea of it being the same bit of data
  20.    (essentially) taking on several forms as it proceeds along the 'pipeline' of
  21.    processing.
  22.  
  23.  
  24. There's a book called "Design Patterns" by Erich Gamma, where the pattern
  25. you seem to be thinking of is called a "Chain of Responsibility".
  26.  
  27. (The book is very useful, I think, but maybe not for beginners.)
  28.  
  29. The idea of this pattern is to define a class `Event' encapsulating 
  30. the data to be processed along the chain. 
  31.  
  32. Then there is an abstract base class `EventHandler' with methods 
  33. `forward(Event&)' and `process(Event&)' and an attribute 
  34. `EventHandler* next_handler'.
  35.  
  36. You can derive several types of event handlers from this class, 
  37. processing the event in a different way.
  38.  
  39. Then you construct instances of these handlers and link them to form a chain.
  40.  
  41. Each handler will process the event in its own style and then forward
  42. it to the next handler.
  43.  
  44. For more details, read the book!
  45.